/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package models.Deck;

import cstAndEnum.*;
import models.Card.*;
import java.util.List;

/**
 *已安装的装备牌
 * @author Invince
 */
public class DeckEquipement extends Deck{
   /*----------Attributs-------------------*/
    /**
     * 已装备的加马
     */
    protected CardEquipementHorsePlus horsePlus;
    /**
     * 已装备的加马
     */
    protected CardEquipementHorseMinus horseMinus;
    /**
     * 已装备的武器
     */
    protected CardEquipementWeapon weapon;
    /**
     * 已装备的防具
     */
    protected CardEquipementArmor armor;


   /*----------Public functions------------*/


 

    /**
     * 装备牌库里加装备，如果不是装备返回false，是装备加入牌库并更新已装备的XX，如果已有该类型的装备，替换之
     * 游戏中一般要用addEquipement();
     * @param indexCardInSouceDeck
     * @param sourceDeck
     * @param abandonDeck
     * @return
     */
    public boolean addEquipement(int indexCardInSouceDeck,Deck sourceDeck,Deck abandonDeck){
        boolean rb=true;
        CST.println("--DeckEquipement--addEquipement: begins--");
        if(indexCardInSouceDeck>sourceDeck.getListCard().size()){
            CST.println("Failed: --DeckEquipement--addEquipement: Error indexCardInSourceDeck--");
            return false;
        }
        Card card=sourceDeck.getListCard().get(indexCardInSouceDeck);
        if(!(card instanceof CardEquipement))
            rb= false;
        if(rb){
            super.drawCard(indexCardInSouceDeck,sourceDeck);//Add card into the deck
            //Check if a such kind of equipement exists already
            //Meanwhile change the equipement
            if(card instanceof CardEquipementArmor){
                this.dropEquipement("CardEquipementArmor",abandonDeck);
                this.setArmor(card);
            }
            if(card instanceof CardEquipementHorsePlus){
                this.dropEquipement("CardEquipementHorsePlus",abandonDeck);
                this.setHorsePlus(card);
            }
            if(card instanceof CardEquipementHorseMinus){
                this.dropEquipement("CardEquipementHorseMinus",abandonDeck);
                this.setHorseMinus(card);
            }
            if(card instanceof CardEquipementWeapon){
                this.dropEquipement("CardEquipementWeapon",abandonDeck);
                this.setWeapon(card);
            }
        }
        else{//if not rb
            CST.println("This is not a equipement.");
        }
        CST.println("--DeckEquipement--addCard: ends--");
        return rb;
    }

    /**
     * 弃装备，如果类型装备不符（typeEquipement）返回false，是装备则弃掉该类型的装备
     * @param typeEquipement
     *                          "CardEquipementArmor"
     *                          "CardEquipementHorsePlus"
     *                          "CardEquipementHorseMinus"
     *                          "CardEquipementWeapon"
     * @param abandonDeck 
     * @return
     */
    public boolean dropEquipement(String typeEquipement,Deck abandonDeck){
        boolean rb=false;
        String s="DeckEquipement--dropEquipement";
        String r="";
        CST.println("--DeckEquipement--dropEquipment: begins--");
        if(typeEquipement.equals("CardEquipementArmor")){
           if(this.armor!=null){
              int indexCard=this.getListCard().indexOf(this.armor);
              super.dropCard(indexCard,abandonDeck);
              this.armor=null;
           }
           rb=true;
        }
        if(typeEquipement.equals("CardEquipementHorsePlus")){
           if(this.horsePlus!=null){
               int indexCard=this.getListCard().indexOf(this.horsePlus);
               super.dropCard(indexCard, abandonDeck);
               this.horsePlus=null;
           }
           rb=true;
        }
        if(typeEquipement.equals("CardEquipementHorseMinus")){
           if(this.horseMinus!=null){
              int indexCard=this.getListCard().indexOf(this.horseMinus);
              super.dropCard(indexCard, abandonDeck);
              this.horseMinus=null;
           }
           rb=true;
        }
        if(typeEquipement.equals("CardEquipementWeapon")){
           if(this.weapon!=null){
              int indexCard=this.getListCard().indexOf(this.weapon);
              super.dropCard(indexCard, abandonDeck);
              this.weapon=null;
           }
           rb=true;
        }
        if(!rb)
            r="Failed: ";
        r+=s;
        CST.println(s);
        CST.println("--DeckEquipement--dropEquipment: ends--");
        return rb;
    }

    /*----------Private functions-----------*/
    /*----------Constructor-----------------*/
    public DeckEquipement(List<Card> listCard) {
        super(listCard);
    }

    /*----------Gets and sets---------------*/
    public CardEquipementArmor getArmor() {
        return armor;
    }

    public void setArmor(Card armor) {
        this.armor = (CardEquipementArmor) armor;
    }

    public CardEquipementHorseMinus getHorseMinus() {
        return horseMinus;
    }

    public void setHorseMinus(Card horseMinus) {
        this.horseMinus = (CardEquipementHorseMinus) horseMinus;
    }

    public CardEquipementHorsePlus getHorsePlus() {
        return horsePlus;
    }

    public void setHorsePlus(Card horsePlus) {
        this.horsePlus = (CardEquipementHorsePlus) horsePlus;
    }

    public CardEquipementWeapon getWeapon() {
        return weapon;
    }

    public void setWeapon(Card weapon) {
        this.weapon = (CardEquipementWeapon) weapon;
    }


}
